package cn.brondfish.icedfish.ui.home;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.google.android.material.navigation.NavigationView;

import cn.brondfish.icedfish.R;
import cn.brondfish.icedfish.databinding.FragmentHomeBinding;
import cn.brondfish.icedfish.ui.home.setting.AppSettingActivity;

public class HomeFragment extends Fragment {

    private FragmentHomeBinding binding;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        HomeViewModel homeViewModel =
                new ViewModelProvider(this).get(HomeViewModel.class);

        binding = FragmentHomeBinding.inflate(inflater, container, false);
        View root = binding.getRoot();
        final NavigationView nav_view = root.findViewById(R.id.nav_view);
        final View homeHeaderBar = nav_view.getHeaderView(0);
        final ImageView avatarView = homeHeaderBar.findViewById(R.id.avatarView);
        avatarView.setOnClickListener(v -> {
            Toast.makeText(getContext(), "头像点击", Toast.LENGTH_SHORT).show();
            // 检查 登录信息，判断是否执行登录功能
        });

        nav_view.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                int menuId = item.getItemId();
                if (menuId == R.id.setting_menu){
                    Intent intent = new Intent(getContext(), AppSettingActivity.class);
                    startActivity(intent);
                    return  true;
                }
                return false;
            }
        });
        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}